package io.mqttpush.getway.common;

import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.util.AsciiString;

/**
 * @author tianzhenjiu
 * @date 2020/9/16 18:27
 */
public class CommonResponse {

    public static final byte[] CONTENT = {'I', 'S', ' ', 'O', 'K'};

    public static final byte[] ByeBye = {'B', 'y', 'e'};

    public static final byte[] unSouppert = "Unsouppert request Method".getBytes();


    public static final byte[] badRequest = "Bad Request".getBytes();


    public static final byte[] serviceError = "serviceError".getBytes();



    public static final AsciiString CONTENT_TYPE = AsciiString.cached("Content-Type");

    public static final AsciiString jsonType = AsciiString.cached("application/json");
    public static final AsciiString AllAccept = AsciiString.cached("*/*");

    public static final AsciiString Accept = AsciiString.cached("Accept");
    public static final AsciiString Host = AsciiString.cached("Host");
    public static final AsciiString CONTENT_LENGTH = AsciiString.cached("Content-Length");
    public static final AsciiString CONNECTION = AsciiString.cached("Connection");
    public static final AsciiString KEEP_ALIVE = AsciiString.cached("keep-alive");


    /**
     * ok的请求
     */
    public static HttpResponse okResponse() {
        return new DefaultFullHttpResponse(
                HttpVersion.HTTP_1_1,
                HttpResponseStatus.OK, Unpooled.wrappedBuffer(CONTENT));
    }



    /**
     * bye的请求
     */
    public static HttpResponse byeResponse() {
        return new DefaultFullHttpResponse(
                HttpVersion.HTTP_1_1,
                HttpResponseStatus.OK, Unpooled.wrappedBuffer(ByeBye));
    }

    /**
     * 无效的请求
     */
    public static HttpResponse badResponse() {
        return new DefaultFullHttpResponse(
                HttpVersion.HTTP_1_1,
                HttpResponseStatus.BAD_REQUEST, Unpooled.wrappedBuffer(badRequest));
    }


    /**
     * 不支持
     */
    public static HttpResponse unSouppertResponse() {
        return new DefaultFullHttpResponse(
                HttpVersion.HTTP_1_1,
                HttpResponseStatus.UNSUPPORTED_MEDIA_TYPE, Unpooled.wrappedBuffer(unSouppert));
    }

    /**
     * 服务端错误
     */
    public static HttpResponse serErrResponse() {
        return new DefaultFullHttpResponse(
                HttpVersion.HTTP_1_1,
                HttpResponseStatus.INTERNAL_SERVER_ERROR, Unpooled.wrappedBuffer(serviceError));
    }
}
